package com.zbkj.crmeb.enums;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Objects;

/**
 * 身份类型
 *
 * @author lvmd
 * @date 2022-02-16
 */
public enum IdentityTypeEnum implements IEnum<Integer> {

    /**
     * 超级管理员
     */
    SUPPER_ADMIN(-1, "超级管理员"),
    /**
     * 平台身份
     */
    PLATFORM(1, "平台"),
    /**
     * 商家身份
     */
    MERCHANT(2, "商家"),
    /**
     * 一级服务商身份
     */
    AGENCY_ONE(3, "一级服务商"),
    /**
     * 二级服务商身份
     */
    AGENCY_TWO(4, "二级服务商"),
    /**
     * 供应商身份
     */
    SUPPLER(5, "供应商身份"),

    ;

    private final Integer code;
    private final String msg;

    IdentityTypeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static IdentityTypeEnum valueOf(Integer code) {
        for (IdentityTypeEnum value : values()) {
            if (code.equals(value.getCode())) {
                return value;
            }
        }
        return IdentityTypeEnum.PLATFORM;
    }

    @Override
    @JsonValue
    public Integer getValue() {
        return code;
    }

    /**
     * 根据code得到枚举的Value
     *
     * @param code
     * @return
     */
    public static String getEnumValue(Integer code) {
        if (Objects.isNull(code)){
            return IdentityTypeEnum.PLATFORM.getMsg();
        }
        IdentityTypeEnum[] logisticsTypeEnums = IdentityTypeEnum.values();
        for (IdentityTypeEnum logisticsTypeEnum : logisticsTypeEnums) {
            if (code.equals(logisticsTypeEnum.getCode())) {
                return logisticsTypeEnum.getMsg();
            }
        }
        return null;
    }

}

